package com.cy.milktea.pojo;

import com.cy.milktea.pojo.System.BaseObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@EqualsAndHashCode(callSuper = true)//将其父类属性也进行比较
@ToString(callSuper = true)//显示其父类属性
@Data
public class Drink extends BaseObject implements Serializable {

    private static final long serialVersionUID = 6849794400754667352L;

    private Integer id;  //--------------------->饮品编号
    private String name;  //-------------------->饮品名称
    private String image;  //------------------->饮品图片路径
    private String sellPoint;  //--------------->饮品卖点
    private String cupSize;  //----------------->杯号
    private String tempJsonStr;  //------------->可选温度列表json字符串,也用于接受微信小程序所选的单个温度选项
    private String sweetnessJsonStr;  //-------->可选甜度列表json字符串,也用于接受微信小程序所选的单个甜度选项
    private Long price;  //--------------------->单品价格(分)
    private Integer status; //------------------>饮品状态 0:下架  1:上架

    private List<String> temps;  //------------->可选温度列表
    private List<String> sweetnessList;  //----->可选甜度列表
    private List<Entremets> entremetsList;  //-->可选配料列表
    private List<Integer> entremetsIds;  //----->可选配料的id列表
    private MultipartFile file;  //------------->图片文件


    public void tempstToJsonStr() {
        try {
            if (this.temps == null || this.temps.size() == 0) return;
            this.tempJsonStr = new ObjectMapper().writeValueAsString(this.temps);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    public void sweetnessListToJsonStr() {
        try {
            if (this.sweetnessList == null || this.sweetnessList.size() == 0) return;
            this.sweetnessJsonStr = new ObjectMapper().writeValueAsString(this.sweetnessList);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    public void tempJsonStrToList() {
        try {
            if (this.tempJsonStr == null || "".equals(this.tempJsonStr)) return;
            this.temps = new ObjectMapper().readValue(this.tempJsonStr, ArrayList.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    public void sweetnessJsonStrToList() {
        try {
            if (this.sweetnessJsonStr == null || "".equals(this.sweetnessJsonStr)) return;
            this.sweetnessList = new ObjectMapper().readValue(this.sweetnessJsonStr, ArrayList.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

}
